/**  
 * StartMaiguoPersonalWebMain.java
 * com.maiguo.web.runntime
 * 
 * @author gaoqs
 * @date 2015年3月5日 上午10:48:28
 * 版权所有
 */
package com.kuaiying.kuai.ying.runtime;


import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.core.JFinal;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.plugin.ehcache.EhCachePlugin;
import com.kuaiying.kuai.ying.beetl.BeetlRenderFactory;
import com.kuaiying.kuai.ying.controller.IndexController;
import com.kuaiying.kuai.ying.controller.user.UserController;
import com.kuaiying.kuai.ying.controller.admin.AdminController;
import com.kuaiying.kuai.ying.controller.printshop.PrintshopController;
import com.kuaiying.kuai.ying.controller.shop.shopController;
import com.kuaiying.kuai.ying.model.user.UserModel;
import com.kuaiying.kuai.ying.model.yangzhengma.YangzhengmaModel;
import com.kuaiying.kuai.ying.model.admin.AdminModel;
import com.kuaiying.kuai.ying.model.leaflet.LeafletModel;
import com.kuaiying.kuai.ying.model.print_file.PrintfileModel;
import com.kuaiying.kuai.ying.model.print_shop.PrintshopModel;
import com.kuaiying.kuai.ying.model.shop.ShopModel;
import com.kuaiying.kuai.ying.model.task_id.TaskidModel;
import com.kuaiying.kuai.ying.model.school.SchoolModel;
import com.kuaiying.kuai.ying.model.sign.SignModel;

/**
 * 启动jfinal
 *
 * @author gaoqs	
 * @date 2015年3月5日 上午10:48:28
 */

public class StartWebMain extends JFinalConfig {

    /**
     * 配置常量
     */
    public void configConstant(Constants me) {
        // 加载少量必要配置，随后可用getProperty(...)获取值
        loadPropertyFile("db.properties");

        boolean isLoacal = getPropertyToBoolean("devMode", false);
        me.setDevMode(isLoacal);
        
        me.setMainRenderFactory(new BeetlRenderFactory());
        me.setError404View("common/404.html");
        me.setError500View("common/500.html");

    }

    /**
     * 配置controller路由
     */
    public void configRoute(Routes me) {
        me.add("/", IndexController.class, "/index"); // 首页controller
        me.add("/user", UserController.class); //用户controller
        me.add("/admin", AdminController.class); //后台用户controller
        me.add("/printshop", PrintshopController.class); //打印店用户controller
        me.add("/shop", shopController.class); //商户controller
    }

    /**
     * 配置插件
     */
    public void configPlugin(Plugins me) {
        // 配置C3p0数据库连接池插件
        C3p0Plugin c3p0Plugin = new C3p0Plugin(getProperty("jdbcUrl"), getProperty("user"), getProperty("password").trim());
        me.add(c3p0Plugin);

        // 配置ActiveRecord插件
        ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
        me.add(arp);
        arp.addMapping("user", "user_id",UserModel.class); // 用户model
        arp.addMapping("admin", AdminModel.class); // admin用户model
        arp.addMapping("leaflet","leaflet_id", LeafletModel.class); // admin用户model
        arp.addMapping("print_file", "file_id",PrintfileModel.class); // admin用户model
        arp.addMapping("print_shop", "print_shop_id",PrintshopModel.class); // admin用户model
        arp.addMapping("shop", "shop_id",ShopModel.class); // admin用户model
        arp.addMapping("task_id","task_id", TaskidModel.class); // admin用户model
        arp.addMapping("school","school_id", SchoolModel.class); // school用户model
        arp.addMapping("yanzhengma", YangzhengmaModel.class); // school用户model
        arp.addMapping("sign", SignModel.class); // 签到用户model
        // 缓存
//        me.add(new EhCachePlugin());
    }

    /**
     * 配置全局拦截器
     */
    public void configInterceptor(Interceptors me) {

    }

    /**
     * 配置处理器
     */
    public void configHandler(Handlers me) {

    }

    /**
     * 建议使用 JFinal 手册推荐的方式启动项目 运行此 main 方法可以启动项目，此main方法可以放置在任意的Class类定义中，不一定要放于此
     */
    public static void main(String[] args) {
        JFinal.start("src/main/webapp", 8080, "/", 5);
    }

}
